<?php
$file = dirname(__FILE__);
$file = substr($file,0,stripos($file, "wp-content"));
require($file . "/wp-load.php");
global $wpdb,$prd_db_table_name;

			$checkinitstock =  '';
			$color 		= '';
			$size 		= '';
			$attribute3 = '';
			$attribute4 = '';
			$attribute5 = '';
			$attribute6 = '';
			$attribute7 = '';
			$attribute8 = '';
			$attribute9 = '';
			$attribute10 = '';

			if(isset($_REQUEST['color']) && $_REQUEST['color']!= '')
				$color = str_replace("amp",'+',$_REQUEST['color']);
			
			if(isset($_REQUEST['size']) && $_REQUEST['size']!= '')
				$size = str_replace("amp",'+',$_REQUEST['size']);

			if(isset($_REQUEST['attribute3']) && $_REQUEST['attribute3']!= '')
				$attribute3 = str_replace("amp",'+',$_REQUEST['attribute3']);
			
			if(isset($_REQUEST['attribute4']) && $_REQUEST['attribute4']!='')
				$attribute4 = str_replace("amp",'+',$_REQUEST['attribute4']);
			
			if(isset($_REQUEST['attribute5']) && $_REQUEST['attribute5']!='')
				$attribute5 = str_replace("amp",'+',$_REQUEST['attribute5']);
			
			if(isset($_REQUEST['attribute6']) && $_REQUEST['attribute6']!='')
				$attribute6 = str_replace("amp",'+',$_REQUEST['attribute6']);
			
			if(isset($_REQUEST['attribute7']) && $_REQUEST['attribute7']!='')
				$attribute7 = str_replace("amp",'+',$_REQUEST['attribute7']);
				
			if(isset($_REQUEST['attribute8']) && $_REQUEST['attribute8']!='')
				$attribute8 = str_replace("amp",'+',$_REQUEST['attribute8']);
				
			if(isset($_REQUEST['attribute9']) && $_REQUEST['attribute9']!='')
				$attribute9 = str_replace("amp",'+',$_REQUEST['attribute9']);
				
			if(isset($_REQUEST['attribute10']) && $_REQUEST['attribute10']!='')
				$attribute10 = str_replace("amp",'+',$_REQUEST['attribute10']);
			
			$js_string = "";
			$product_id = $_REQUEST['pid'];
			$customename = array('size','color','attribute3','attribute4','attribute5','attribute6','attribute7','attribute8','attribute9','attribute10');
			$result = $wpdb->get_results("select * from  $prd_db_table_name where  pid = ".$_REQUEST['pid']);
			
			global $General,$prd_db_table_name;
			
			$attribute_array = $General->product_current_orders_count($product_id,array('attribute'=>'1'));

			$att_str = $General->get_attribute_str($attribute_array,$product_id);
			$returnarray = array();
			$data = get_post_meta( $product_id, 'key', true );
			
			for($i=0;$i<count($customename);$i++)
			{
				$customval .= $data[$customename[$i]].",";
				$customval_stock .= substr($data[$customename[$i].'_stock'],1,strlen($data[$customename[$i].'_stock'])).",";
			}
			
			$customval_stock_arr = (explode(',',$customval_stock));
			
			for($l=0;$l<count($customval_stock_arr);$l++)
			{
				if($customval_stock_arr[$l] == '')
					$customval_stock_arr[$l] = 0;

				if($customval_stock_arr[$l] != '')
				{
					$checkinitstock = '1';
				}
			}
			
			if($select_text=='')
			{
				$select_text = $customename;
			}

			if($customval != '')
			{
				if($customeId == '')
				{
					$customeId = $customename;
				}
				$customArr1 = explode(',',$customval);

				for($i=0;$i<count($customArr1);$i++)
				{
					$cust_att =trim(preg_replace('/[(]([+-]+)(.*)[)]/','',$customArr1[$i].$product_id));

					if($customval_stock_arr[$i]!=''  )
					{
					for($j=0;$j<count($result);$j++)
					{	
						$count = 0;
						$pdescarr = explode(",",$result[$j]->pdesc);
						for($k=0;$k<count($pdescarr);$k++)
						{	
							if(( $pdescarr[$k].$product_id == $color.$product_id || $pdescarr[$k].$product_id == $size.$product_id || $pdescarr[$k].$product_id == $attribute3.$product_id || $pdescarr[$k].$product_id == $attribute4.$product_id || $pdescarr[$k].$product_id == $attribute4.$product_id || $pdescarr[$k].$product_id == $attribute5.$product_id || $pdescarr[$k].$product_id == $attribute5.$product_id || $pdescarr[$k].$product_id == $attribute7.$product_id || $pdescarr[$k].$product_id == $attribute8.$product_id || $pdescarr[$k].$product_id == $attribute9.$product_id || $pdescarr[$k].$product_id == $attribute10.$product_id ))
							{
								if($result[$j]->prd_qty!='')
								{
									$count = $count + $result[$j]->prd_qty;
								}
							}
						}
					}

					if(( $customArr1[$i].$product_id == $color.$product_id || $customArr1[$i].$product_id == $size.$product_id || $customArr1[$i].$product_id == $attribute3.$product_id || $customArr1[$i].$product_id == $attribute4.$product_id || $customArr1[$i].$product_id == $attribute4.$product_id || $customArr1[$i].$product_id == $attribute5.$product_id || $customArr1[$i].$product_id == $attribute5.$product_id || $customArr1[$i].$product_id == $attribute7.$product_id || $customArr1[$i].$product_id == $attribute8.$product_id || $customArr1[$i].$product_id == $attribute9.$product_id || $customArr1[$i].$product_id == $attribute10.$product_id ))
					{
							$cust_stock = $customval_stock_arr[$i] - substr_count($att_str,','.$cust_att) - ($count);

						if($cust_stock >= $_REQUEST['qty'])
						{ 
							$js_string = "true";
						}
						else
						{ 
							$js_string = "false";
						}
					}
			}

			elseif($data['initstock'] != '' && $checkinitstock == '')
			{
				for($j=0;$j<count($result);$j++)
				{
					$pdescarr = explode(",",$result[$j]->pdesc);
					for($k=0;$k<count($pdescarr);$k++)
					{
						if(( $pdescarr[$k] == $color || $pdescarr[$k] == $size || $pdescarr[$k] == $attribute3 || $pdescarr[$k] == $attribute4 || $pdescarr[$k] == $attribute4 || $pdescarr[$k] == $attribute5 || $pdescarr[$k] == $attribute5 || $pdescarr[$k] == $attribute7 || $pdescarr[$k] == $attribute8 || $pdescarr[$k] == $attribute9 || $pdescarr[$k] == $attribute10 ))
						{
							if($result[$k]->prd_qty!='')
							{
								$count = $count + $result[$k]->prd_qty;
							}
						}
					}
				}

				$cust_stock = $data['initstock']-substr_count($att_str,','.$cust_att)-($count);

				if($cust_stock >= $_REQUEST['qty'])
				{
					$js_string = "true";
				}
				else
				{
					$js_string = "false";
				}
			}
		}
	}
	print_r($js_string);exit;
?>